package xh.server.commands.impl;

import xh.server.PlayerController;
import xh.server.commands.PlayerCommand;
import xh.server.commands.PlayerOperation;
import xh.util.Global;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by Administrator on 2016/6/25.
 */
public class Play implements PlayerCommand {

    private URL file;


    public PlayerOperation getPlayerOperation() {
        return PlayerOperation.Play;
    }

    public Object doCommand() {
        try {
            PlayerController.controller().play(file);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    public void initFromParams(String[] params) {

        File f = new File(Global.MusicDir, params[0]);
        try {
            file = f.toURI().toURL();
            return;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    public URL getFile() {
        return file;
    }

    public void setFile(URL file) {
        this.file = file;
    }
}
